package cn.xm.utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class MD5 {
	public static final String HASH_ALGORITHM = "SHA-1";
	public static final int HASH_INTERATIONS = 1024;
	public static final int SALT_SIZE = 8;
	
	private static final String SHA1 = "SHA-1";
	private static final String MD5 = "MD5";

	/**
	 * 生成安全的密码
	 */
	public static String entryptPassword(String plainPassword) {
		String result = null;
		try {
			MessageDigest digest = MessageDigest.getInstance(MD5);
			byte[] input = plainPassword.getBytes();
			digest.update(input);
//			byte[] ouput  = digest.digest(input);
			result = new BigInteger(1, digest.digest()).toString(16);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static void main(String[] args) {
		System.out.println(entryptPassword("123"));
	}
}
